package Controller.Customer;


import Dao.CustomerDao;
import Dto.Customer;
import Service.CustomerService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet(name = "preUpdateCustomer", value = "/preUpdateCustomer")
public class PreUpdateCustomer extends HttpServlet {
    private CustomerService customerService = new CustomerService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer id = Integer.valueOf(request.getParameter("id"));
        CustomerDao customerDao = new CustomerDao();
        try {
            List<String> list = customerDao.selectFirm(); // Assuming this method exists and is correctly implemented
            Customer customer = customerService.preUpdateCustomer(id);
            request.setAttribute("list", list);
            request.setAttribute("customer", customer);
            request.getRequestDispatcher("/updateCustomer.jsp").forward(request, response);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}